package com.atguigu.gmall.mq.reveiver;

import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * title:
 * author: Gyh
 * date:2023-05-08 19:49
 * Description:
 */
@Slf4j
@Component
public class ConfirmReceiver {

    @SneakyThrows
    @RabbitListener(
            bindings = @QueueBinding(
                    exchange = @Exchange("exchange.confirm"),
                    value = @Queue("confirm.queue"),
                    key = "routing.confirm"
            )
    )
    public void receiverConfirmMessage(String msg, Channel channel, Message message){
        log.info("消费之接收到消息:()",msg);
        //开启手动确认,参数1:投递消息消息标签,参数2:是否批量确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
